/*******************************************************************************

                           TMenu 缓冲区DEMO

*******************************************************************************/
#include "TMenu_Buf.h"
#include <string.h>

#ifndef LV_LOG_USER //TGUI模式且未重定向时
  #define LV_LOG_USER(...) do {}while(0)
#endif

#ifdef TMENU_TEST_ALL    //集中测试时
  extern const TMenu_t TMenu_SubTop;      //子菜单作为总菜单
  #define  _PARENT_MENU  &TMenu_SubTop   //父菜单
#else
  #define _PARENT_MENU  NULL   //本层即为总菜单
#endif

/*******************************************************************************
                              本层总菜单实现
*******************************************************************************/
static unsigned char _Key = 0;

static void _Notify(unsigned char Type,//通报类型
                       //根据菜单类型输入的输入输出数据区
                       //该区域结构在控件里定义,直接指针转换即可
                       void *pv)
{
  struct _BufUser *pUser = pv;

  //按键响应
  if(Type == TM_NOTIFY_BUF_KEY){
    switch(pUser->Key){
      case TGUI_KEY_ESCAPE: //退出键
        if(_Key) _Key = 0; //退至首页
        else{ //退出本菜单
          pUser->Notify = TM_BUF_NOTIFY_EXIT_FLAG;
          return;
        }
       break;
      case TGUI_KEY_ENTER: //自动翻页
        _Key++;
        if(_Key > 2) _Key = 0;
        break;
      case TGUI_KEY_UP:
      case TGUI_KEY_LEFT:
      case TGUI_KEY_PAGEUP: //均为上一页
        _Key = 1;
        break;
      case TGUI_KEY_DOWN:
      case TGUI_KEY_RIGHT:
      case TGUI_KEY_PAGEDOWN: //均为下一页
        _Key = 2;
        break;
      default: break;
    }
    pUser->Notify = TM_BUF_NOTIFY_DISP; //更新整屏显示
    return;
  }
  //更新显示缓冲区
  if(Type == TM_NOTIFY_GET_DATA){
    char *pBuf = pUser->pBuf;
    if(_Key == 0){//进入时
      strcpy(pBuf, "人工按拼音一个个查找缺失的字(到m):n"\
         "黯鳌鏖魃掰剥鞴妣髀鳔髟髌鬓炳剥黪猖魑楚黜靼鞑逮黛骶叠髑黩二鼢服铪骼羹佝鞲酤鹘鳏簋鳜帼哈铪撖鼾颃骺湖鹘鬟麾"\
         "箕髻麂铪件鞯骱浸泾鬏鞫峻麇铪髁骷髋纩傀髡濑鳓俐鳢黧鬣蔺麟窿髅谩鳗鞔蟒髦魅縻麋鳘摸麽 \n"\
          "This function is used to display read-only text "\
            "information such as help,\n "\
            "and can be flipped up and down with the up and down keys");
    }
    else if(_Key == 1){//上一页
      strcpy(pBuf, "This is page 1");
    }
    else if(_Key == 2){//下一页
      strcpy(pBuf, "This is page 2");
    }
    else strcpy(pBuf, "This is page n");
  }
}

//--------------------------顶层菜单结构----------------------------
const TMenu_t TMenu_BufTop = {//顶层菜单结构
  TMTYPE_BUF,     //菜单类型为缓冲区模式
  0,              //0
  "Demo Buf",     //菜单头,为NULL时从回调里读取
  _PARENT_MENU,   //自已的父菜单
  NULL,           //NULL
  _Notify,        //与用户空间交互的通报函数
};
